//用户相关仓库
import { defineStore } from 'pinia'
//引入数据类型
import type { loginFormData } from '@/api/user/type'
// 引入接口
import { reqLogin } from '@/api/user'
import {UserState} from './types/type'
import { constantRouter } from '@/router/routers'
let useUserStore = defineStore('User', {
    state: ():UserState => ({
        token: localStorage.getItem('token'),
        menuRoutes:constantRouter
    }),
    // 异步逻辑
    actions: {
        async userLogin(loginForm: loginFormData) {
            const res = reqLogin(loginForm)
            console.log(res.error_code,'res.error_code')
            if (res.error_code === 0) {
                this.token = res.data.token
                localStorage.setItem('token', res.data.token)
                return "ok"
            } else{
                return "error"
            }
        }
    },
    // 计算属性
    getters: {

    }
})
export default useUserStore